package com.company;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author Corgile
 */
public class Main {

	public static void main(String[] args) throws IllegalAccessException,
			InvocationTargetException, IntrospectionException {
		// write your code here
		SomeBean bean = new SomeBean("AAA", 0x111, (short) 8, 11.11F, 'G');
		Field[] fields = bean.getClass().getDeclaredFields();

		for (Field field : fields) {
			PropertyDescriptor dp = new PropertyDescriptor(field.getName(), bean.getClass());
			Method getter = dp.getReadMethod();
			// 调用getter方法获值
			Object val = getter.invoke(bean);
			if (null != val) {
				System.out.println(field.getType() + ", " + field.getName() + " = " + val);
			}
		}
	}
}
